﻿using ZquenceStudio3Host.DspPlugins.Synthesizers.Nodesizer.Engine;

namespace DefaultDspPlugins.Common.Modulizer.Engine.Modules.Analog
{
    [ModuleDisplay("Diod")]
    public class DiodModule : BaseModule
    {
        public readonly ModuleInput In;
        public readonly ModuleOutput Out;
        
        public DiodModule(ModuleManager manager)
            : base(manager)
        {
            // Add input and outputs to module.
            AddInput(In = new ModuleInput("In", IOType.AudioOrWaveform, this));
            
            AddOutput(Out = new ModuleOutput("Out", IOType.AudioOrWaveform, this));
        }

        public override void Process()
        {
            if (In.IsConnected)
            {
                for (int i = 0; i < Out.AudioBuffer.Length; i++)
                {
                    double valueIn = In.FromOutput.AudioBuffer[i];
                    Out.AudioBuffer[i] = valueIn > 0 ? valueIn : 0;
                }
            }
        }
    }
}
